package main

import (
	"fmt"
	"time"
)

func main() {
	var m = []int{1, 2, 3, 4, 5}
	for i, v := range m {
		go func(i, v int) {
			fmt.Print(i, "=>", v, ",") //4=>5,3=>4,2=>3,0=>1,1=>2,(输出顺序不确定)
		}(i, v)
	}
	time.Sleep(time.Second * 1)
	fmt.Println()

	//channel
	ch1 := make(chan int, 3)
	ch1 <- 2
	ch1 <- 1
	ch1 <- 3
	data1 := <-ch1
	data2 := <-ch1
	data3 := <-ch1
	fmt.Printf("从channel中接收的元素: %v,%v,%v \n", data1, data2, data3) // 2,1,3
}
